package com.sports.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sports.entity.Item;
import com.sports.entity.Score;
import com.sports.mapper.ScoreMapper;
import com.sports.service.ItemService;
import com.sports.mapper.ItemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author LZL
* @description 针对表【t_item】的数据库操作Service实现
* @createDate 2024-03-21 20:55:04
*/
@Service
public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item>
    implements ItemService{


    @Autowired
    private ItemMapper itemMapper;
    @Override
    public List<Item> getItemListByName(String name,Integer current) {
        Page<Item> itemPage = new Page<>(current, 5);
        LambdaQueryWrapper<Item> wrapper = Wrappers.<Item>lambdaQuery()
                .like(Item::getItemName, name);
        Page<Item> itemPage1 = itemMapper.selectPage(itemPage, wrapper);
        return itemPage1.getRecords();
    }

    @Override
    public Page<Item> getItemPageList(String name, Integer current, Integer size) {
        Page<Item> itemPage = new Page<>(current, size);
        return  this.lambdaQuery().like(Item::getItemName, name).page(itemPage);
    }


//    @Autowired
//    private ScoreMapper scoreMapper;
//    @Override
//    public Boolean signUp(Integer athletesId, Integer itemId) {
//
//        LambdaQueryWrapper<Score> eq = Wrappers.<Score>lambdaQuery().eq(Score::getAthletesId, athletesId)
//                .eq(Score::getItemId, itemId);
//        if (scoreMapper.selectOne(eq) != null){
//            return false;
//        }
//        Score sc = new Score();
//        sc.setAthletesId(athletesId);
//        sc.setItemId(itemId);
//        scoreMapper.insert(sc);
//        return true;
//    }
}




